<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../../js/jQuery/jquery-1.8.3.min.js"></script>
<script src="../../js/jQuery/jquery.form.js"></script>
<script type="text/javascript">
    function upload() {
        if($("#fileName").val() == '') {
            top.isc.showMessage("请选择文件", top.isc.OBMessageBar.TYPE_ERROR);
            return;
        }
        var tabId = request("tabId");
        var dataId = request("dataId");
        var options = {
            url: top.OB.Application.contextUrl +
                "./org.openbravo.client.kernel?_action=com.basis.handler.FileUploadHandler&dataId=" + dataId + "&tabId=" + tabId,
            type: 'POST',
            dataType:'json',
            data:{},
            async: false,
            success: function(data) {
                if(data.result) {
                    top.OB.MesActionButton.refreshView();
                    top.isc.showMessage(data.desc,top.isc.OBMessageBar.TYPE_SUCCESS);
                    top.OB.Layout.ClassicOBCompatibility.Popup.close("file_Upload_Popup");
                }else{
                    top.isc.showMessage(data.desc,top.isc.OBMessageBar.TYPE_INFO);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                top.isc.showMessage("上传失败", top.isc.OBMessageBar.TYPE_ERROR);
            }
        };
        $("#importFile").ajaxSubmit(options);

    }
    function request(name) {
        var url = window.location.href;
        var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
        var url_paraObj = {}
        for (var i = 0; i < paraString.length; i++) {
            var index = paraString[i].indexOf("=");
            try {
                url_paraObj[paraString[i].substring(0, index)] = decodeURI(paraString[i].substring(index + 1));
            } catch (e) {
                url_paraObj[paraString[i].substring(0, index)] = paraString[i].substring(index + 1);
            }
        }
        return url_paraObj[name];
    }
</script>
</head>
<body>
<form name="importFile" id="importFile" method="post" enctype="multipart/form-data">
    <div style="padding: 10px;">
        <%
        String[] names = request.getParameter("names").split(",");
        String[] fields = request.getParameter("fields").split(",");
        for (int i = 0;i < names.length; i ++) {
        %>
        <div style="height: 30px;line-height: 30px;clear: both;">
            <div style="width: 150px;text-align: right;float: left;"><%=names[i] %>：</div>
            <input type="file" name="<%=fields[i] %>" id="<%=fields[i] %>" /></div>
        <%
        }
        %>
    </div>
    <div style="padding: 20px;position: absolute;right: 30px;bottom: 20px;">
        <button onclick="upload()" style="padding: 5px 15px;background-color: #4D7607;border: 0px;color: #fff;">上传</button>
    </div>
</form>
</body>
</html> 
